package com.cxrj.zhsq.propertyManage.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cxrj.zhsq.propertyManage.dao.PropertyPaymentMapper;
import com.cxrj.zhsq.propertyManage.entity.PropertyPayment;
import com.cxrj.zhsq.propertyManage.service.PropertyPaymentService;

@Service
public class PropertyPaymentServiceImpl implements PropertyPaymentService {

	@Resource
	private PropertyPaymentMapper propertyPaymentMapper;

	@Override
	public Map<String, Object> insertPropertyPayment(PropertyPayment propertyPayment) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		sqlMap.put("code", propertyPayment.getCode());
		sqlMap.put("communityId", propertyPayment.getCommunityId());
		Integer c = 0;
		PropertyPayment oldPayment = propertyPaymentMapper.selectByCode(sqlMap);
		if (oldPayment == null) {
			propertyPayment.setId(UUID.randomUUID().toString());
			c = propertyPaymentMapper.insertSelective(propertyPayment);
		} else {
			c = propertyPaymentMapper.updateByCode(propertyPayment);
		}
		resultMap.put("result", 0);
		if (c > 0) {
			resultMap.put("result", 1);
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> selectPropertyPaymentByCode(String code, String communityId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		sqlMap.put("code", code);
		sqlMap.put("communityId", communityId);
		resultMap.put("payment", propertyPaymentMapper.selectByCode(sqlMap));
		return resultMap;
	}
}
